package priv.yiyuan.example.design.visitor;

import org.junit.Test;

/**
 * @author YiYuan
 * @data 2025/8/1
 * @apoNote
 */
public class FileSystemDemo {

    @Test
    public void test_file() {
        Directory root = new Directory("root");
        Directory src = new Directory("src");
        Directory main = new Directory("main");
        Directory java = new Directory("java");
        Directory resource = new Directory("resource");

        File appJava = new File("App.java", 100);
        File utilJava = new File("Util.java", 150);
        File configXml = new File("config.xml", 50);
        File readmeMd = new File("README.md", 200);

        root.addComponent(src);
        root.addComponent(readmeMd);

        src.addComponent(main);

        main.addComponent(java);
        main.addComponent(resource);

        java.addComponent(appJava);
        java.addComponent(utilJava);

        resource.addComponent(configXml);

        System.out.println("\n--- Calculating Total Size ---");
        SizeCalculatingVisitor sizeVisitor = new SizeCalculatingVisitor();
        root.accept(sizeVisitor);
        System.out.println("Total size of file system: " + sizeVisitor.getTotalSize() + " bytes");

        System.out.println("\n--- Listing All File Names ---");
        FileNameListingVisitor nameVisitor = new FileNameListingVisitor();
        root.accept(nameVisitor);
        System.out.println("All file names: " + nameVisitor.getFileNames());

    }

}
